package com.sandy.springdata

import org.hibernate.annotations.GenericGenerator

import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Index
import javax.persistence.Table

// 声明Class映射student表,创建birthday字段索引
@Entity
@Table(name = "student", indexes = @Index(name = "birthday_index", columnList = "birthday"))
class Student {
    // id字段,长度32,使用uuid自动生成策略
    @Id
    @Column(length = 36)
    @GeneratedValue(generator = "uuidGenerator")
    @GenericGenerator(name = "uuidGenerator", strategy = "org.hibernate.id.UUIDGenerator")
    String studentId

    // 唯一索引,不能为空
    @Column(length = 10, unique = true, nullable = false)
    String studentNo

    @Column(length = 32)
    String name

    // 枚举类型在表中使用int存储
    SexType sex

    Date birthday
}
